package com.kgc.server.controller;

import com.kgc.server.pojo.EasybuyCar;
import com.kgc.server.service.EasybuyCarService;
import com.kgc.server.util.ResponseMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


@Controller
public class BuyCarController {

    private Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private EasybuyCarService easybuyCarService;


    @RequestMapping("addProductToCar")
    @ResponseBody
    @CrossOrigin
    public ResponseMessage addProductToCar(EasybuyCar easybuyCar){
        logger.info("BuyCarController easybuyCar params:"+easybuyCar);
        ResponseMessage responseMessage = easybuyCarService.addProductToCar(easybuyCar);
        return responseMessage;
    }

    @ResponseBody
    @RequestMapping("selectUserCar")
    @CrossOrigin
    public ResponseMessage selectUserCar(String userId){
        logger.info("BuyCarController selectUserCar param: userId:"+userId);
        ResponseMessage responseMessage = easybuyCarService.selectUserCar(userId);
        return responseMessage;
    }

    @ResponseBody
    @RequestMapping("updateUserCar")
    @CrossOrigin
    public ResponseMessage updateUserCar(EasybuyCar easybuyCar){
        logger.info("BuyCarController updateUserCar params: easybuyCar:"+easybuyCar);
        ResponseMessage responseMessage = easybuyCarService.updateUserCar(easybuyCar);
        return responseMessage;
    }

    @ResponseBody
    @RequestMapping("deleteCarById")
    @CrossOrigin
    public ResponseMessage deleteCarById(String id){
        logger.info("BuyCarController deleteCarById param: id:"+id);
        ResponseMessage responseMessage = easybuyCarService.deleteCarById(id);
        return responseMessage;
    }

}
